﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script src="../js/jquery-3.2.1.js"></script>
    <script language="javascript" type="text/javascript">
        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {
                console.log(result)

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员管理") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号管理") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号管理") ==-1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") ==-1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表管理") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }
            }
        });

    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="../index.html" class="index_off"></a></li>
        <li id="lia1"><a href="rolelist" class="role_off"></a></li>
        <li id="lia2"><a href="adminlist" class="admin_off"></a></li>
        <li id="lia3"><a href="fee" class="fee_on"></a></li>
        <li id="lia4"><a href="accountlist" class="account_off"></a></li>
        <li id="lia5"><a href="servicelist" class="service_off"></a></li>
        <li id="lia6"><a href="bill" class="bill_off"></a></li>
        <li id="lia7"><a href="report" class="report_off"></a></li>
        <li><a href="userinfo" class="information_off"></a></li>
        <li><a href="changepsw" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--排序-->
        <div class="search_add">
            <div>
                <!--<input type="button" value="月租" class="sort_asc" onclick="sort(this);" />-->
                <input type="button" value="基费" class="sort_asc" onclick="sort(this);"/>
                <input type="button" value="时长" class="sort_asc" onclick="sort(this);"/>
            </div>
            <input type="button" value="增加" class="btn_add" onclick="location.href='/add';"/>
        </div>
        <!--启用操作的操作提示-->
        <div id="operate_result_info" class="operate_success">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            删除成功！
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th>资费ID</th>
                    <th class="width100">资费名称</th>
                    <th>基本时长</th>
                    <th>基本费用</th>
                    <th>单位费用</th>
                    <th>创建时间</th>
                    <th>开通时间</th>
                    <th class="width50">状态</th>
                    <th class="width200"></th>
                </tr>
                <tbody id="tbody">

                </tbody>
            </table>
            <p>业务说明：<br/>
                1、创建资费时，状态为暂停，记载创建时间；<br/>
                2、暂停状态下，可修改，可删除；<br/>
                3、开通后，记载开通时间，且开通后不能修改、不能再停用、也不能删除；<br/>
                4、业务账号修改资费时，在下月底统一触发，修改其关联的资费ID（此触发动作由程序处理）
            </p>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <p>版权所有(C)云科技有限公司</p>
</div>
</body>
<script src="../js/jquery-3.2.1.js"></script>
<script>
    function addNewTR(cost) {
        stime = cost.startime
        if(stime==null){
            stime = "未开通"
        }
        var tr = $("<tr><td>" + cost.costId + "</td><td><a href=/detail?costid="+cost.costId+">" + cost.name + "</td><td>"
                + cost.baseDuration + "</td><td>" + cost.baseCost + "</td><td>" + cost.unitCost + "</td><td>"
                + cost.creatime + "</td><td>" + stime + "</td><td>" + cost.status + "</td><td><span id='operation"+cost.costId+"'>"
                + "<input type=button value=启用 class=btn_start onclick=startFee("+cost.costId+"); />"
                + "<input type=button value=修改 class=btn_modify onclick=location.href='/modi?costid="+cost.costId+"'; />"
                + "<input type=button value=删除 class=btn_delete onclick=deleteFee("+cost.costId+"); />"
                + "</span></td></tr>")
        var tab = $("#tbody");
        tab.append(tr);
        if (cost.status == '开'){
            document.getElementById("operation"+cost.costId+"").style.display = "none";
        }
    }
//    getAllMessages();
//    function getAllMessages() {
//        $.ajax({
//            url: "/allcost",
//            type: "post",
//            success: function (result) {
//                for (var i in result) {
//                    var cost = result[i];
//                    addNewTR(cost,i);
//                }
//            }
//        })
//    }

    $.ajax({
        url: "costpage",
        type: "type",
        success: function (result) {
            var roleList = result.list;
            var pages = result.pages;
            var pageNum = result.pageNum;
            var isFirstPage = result.isFirstPage;
            var isLastPage = result.isLastPage;
            for (var i in roleList) {
                var role = roleList[i];
                addNewTR(role);
            }
            $("#pages").append("<a id='up'>上一页</a>")

            for (var i = 1; i < pages+1; i++) {
                if (i == pageNum) {
                    $("#pages").append("<a id='" + i + "'; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                } else {
                    $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                }
            }
            $("#pages").append("<a id='down'>下一页</a>")
            if (!isFirstPage) {
                var num = pageNum - 1;
                $("#up").attr("onclick", "changePage(" + num + ")");
            }
            if (!isLastPage) {
                var num = pageNum + 1;
                $("#down").attr("onclick", "changePage(" + num + ")");
            }
        }
    })

    function changePage(pagenum) {

        $.ajax({
            url: "costpage",
            type: "post",
            data: {
                pagenum: pagenum,
            },
            success: function (result) {
                $("#tbody").empty();
                $("#pages").empty();
                var costList = result.list;
                var pages = result.pages;
                var pageNum = result.pageNum;
                var isFirstPage = result.isFirstPage;
                var isLastPage = result.isLastPage;
                for (var i in costList) {
                    var cost = costList[i];
                    addNewTR(cost);
                }
                $("#pages").append("<a id='up'>上一页</a>")
                if (!isFirstPage) {
                    var num = pageNum - 1;
                    $("#up").attr("onclick", "changePage(" + num + ")");
                }
                for (var i = 1; i < pages+1; i++) {
                    if (i == pageNum) {
                        $("#pages").append("<a id=" + i + "; class='current_page'; onclick='changePage(" + i + ")'>" + i + "</a>")
                    } else {
                        $("#pages").append("<a id=" + i + "; onclick='changePage(" + i + ")'>" + i + "</a>")
                    }
                }
                $("#pages").append("<a id='down'>下一页</a>")
                if (!isLastPage) {
                    var num = pageNum + 1;
                    $("#down").attr("onclick", "changePage(" + num + ")");
                }
            }
        })
    }

    //排序按钮的点击事件
    function sort(btnObj) {
        console.log(btnObj)
        if (btnObj.className == "sort_desc") {
            btnObj.className = "sort_asc";
            $("#tbody").empty();
            if (btnObj.value == "基费"){
                $.ajax({
                    url: "/allcostascbybc",
                    type: "post",
                    success: function (result) {
                        for (var i in result) {
                            var cost = result[i];
                            addNewTR(cost,i);
                        }
                    }
                })
            }else {
                $.ajax({
                    url: "/allcostascbybd",
                    type: "post",
                    success: function (result) {
                        for (var i in result) {
                            var cost = result[i];
                            addNewTR(cost,i);
                        }
                    }
                })
            }
        }
        else {
            btnObj.className = "sort_desc";
            $("#tbody").empty();
            if (btnObj.value == "基费"){
                $.ajax({
                    url: "/allcostdescbybc",
                    type: "post",
                    success: function (result) {
                        for (var i in result) {
                            var cost = result[i];
                            addNewTR(cost,i);
                        }
                    }
                })
            }else {
                $.ajax({
                    url: "/allcostdescbybd",
                    type: "post",
                    success: function (result) {
                        for (var i in result) {
                            var cost = result[i];
                            addNewTR(cost,i);
                        }
                    }
                })
            }
        }
    }
    //启用
    function startFee(id) {
        var r = window.confirm("确定要启用此资费吗？资费启用后将不能修改和删除。");
        if (r == true){
            document.getElementById("operate_result_info").style.display = "block";
            $.ajax({
                url:"/start?id="+id,
                type:"post",
                success:function (result) {
//                    alert(result.message)
                    window.location.href = "../fee";
                }
            })
        }
    }
    //删除
    function deleteFee(id) {
        var r = window.confirm("确定要删除此资费吗？");
        if (r == true){
            document.getElementById("operate_result_info").style.display = "block";
            $.ajax({
                url:"/delete?id="+id,
                type:"post",
                success:function (result) {
//                    alert(result.message)
                    window.location.href = "../fee";
                }
            })
        }
    }

</script>
</html>